import axios from 'axios'
import NproGress from 'nprogress'
import { message } from 'antd'
import 'nprogress/nprogress.css'

const http = axios.create({
  timeout: 30000,
  baseURL: 'https://bjwz.bwie.com',
  // 设置最大次数
  retry: 3,
  //   设置重新请求等待的时间
  retryDelay: 1000
})

http.interceptors.request.use((config) => {
  NproGress.start()
  return config
})

http.interceptors.response.use(
  (data) => {
    NproGress.done()
    return data.data
  },
  (error) => {
    console.log(error)
    switch (error.response.status) {
      case 403:
        message.error('无权限访问')
        break
    }
  }
)

export default http
